package com.client;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ws.soap.client.SoapFaultClientException;

import com.pentalog.bo.ExSoapClient;
import com.pentalog.domain.BookRequest;
import com.pentalog.domain.BookResponse;

public class ExClient {
    public static void main(String[] args) throws JAXBException{
    	ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");  
    	ExSoapClient client = (ExSoapClient) ctx.getBean("exClientImpl");  
    	BookResponse BookResponse = null;      	
    	try {  
    	      String id = "OKOK";  
    	      System.out.println("Get person with id=" + id + "...");  
    	      BookResponse = client.getBook(id); 
    	      System.out.println("\tPerson Response " + makeString(BookResponse));  
    	    } catch (SoapFaultClientException se) {  
    	      System.out.println("\t" + se.getMessage());  
    	    }
    	
//    	JAXBContext jc = 
//    	           JAXBContext.newInstance(BookRequest.class);
//    	 
//    	BookRequest customer = new BookRequest();
//    	        customer.setItemCode("OKO");
//    	 
//    	        Marshaller m = jc.createMarshaller();
//    	        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
//    	        m.marshal(customer, System.out);
    }
    

	private static String makeString(BookResponse p) {
		return "[item=" + p.getItemCode() + ", bookname=" + p.getBookName()
				+ ", author=" + p.getAuthor() + "]";
	}
}
